package com.itheima.dao;

import com.itheima.domain.Student;

import java.util.ArrayList;

public class otherStudentDao implements BaseStudentDao{
    private ArrayList<Student>list =new ArrayList<>();
        public boolean addStudent(Student stu) {
            list.add(stu);
                return true;
        }
        public Student[] findAllStudent() {
            Student [] stus=new Student[list.size()];
            for (int i = 0; i < list.size(); i++) {
                stus [i] =list.get(i);
            }
            return stus;
        }

        public void deletStudent(String sid) {
            int idex = getIdex(sid);
            list.remove(idex);
        }
        public int getIdex(String sid){
            int index=-1;
            for (int i = 0; i < list.size(); i++) {
                Student stu=list.get(i);
                if(stu!=null&&stu.getSid().equals(sid)){
                    index=i;
                }
            }
            return index;
        }
        public void updateStudent(String sid, Student stu) {
            int idex = getIdex(sid);
            list.set(idex,stu);
        }

    }


